#include "Projectile.h"

Projectile::Projectile(Point& location)
	:Movables(location, RADIUS_OF_MOVABLE, 1, PROJECTILE, getDefaultBitmap(PROJECTILE_BITMAP)),
	_is_shooting(false)
{}

DetectionResult Projectile::collisionCheck(Movable_type position_type) const
{
	switch(position_type)
	{
	case HOLE:
		return CAN_MOVE;
		break;
	case SAND:
		return COLLISION;
		break;
	case MONSTER:
		return MONSTER_DEAD;
		break;
	case DIGDUG:			//Should never happen!
		return DIGDUG_DEAD;
		break;
	}
	return DIGDUG_DEAD;		//Should never reach here!
}

DetectionResult Projectile::move(Map &map)
{
	DetectionResult move_result = checkMoveInDirection(_location, _direction, map);
	
	if ( move_result == CAN_MOVE)
	{
		int delta_x = delta(_direction).at(0);
		int delta_y = delta(_direction).at(1);
		_location = Point(_location.x() + delta_x, _location.y() + delta_y);
	}
	
	return move_result;
}

void Projectile::allowMove(Direction direction)
{
	_direction = direction;
	_is_shooting = true;
}

void Projectile::stopShot()
{
	_is_shooting = false;
}

bool Projectile::isShooting()
{
	return _is_shooting;
}